<?php
/**
 *  订单记录控制器
 *
 * @author yyx<yyx@vip.deyi.com>
 * @since   2019/01/3 15:10
 * @copyright  deyi.com
 */

namespace Apps\Acp\Controllers;

use Apps\Acp\Models\Order;
use Apps\Common\Constant\BusinessConstant;
use Apps\Common\Controller\AcpBaseController;
use Deyi\Functions\PageFunction;

/**
 * Class LogController
 * @package Apps\Ad\Controllers
 */
class OrderController extends AcpBaseController
{
    public function indexAction()
    {
        $page = PageFunction::getPageAndOffset($this->getParamValue('page', 1, 'int'), BusinessConstant::PAGE_SIZE);
        $stime = strtotime($this->getParamValue('stime', '', 'string'));
        $etime = strtotime($this->getParamValue('etime', '', 'string'));

        $conditions = [];

        if ($stime) {
            $conditions['createtime>='] = $stime;
        }

        if ($etime) {
            $conditions['createtime<='] = $etime;
        }

        $total = Order::getInstance()->countListByConds($conditions);
        $list = [];
        if ($total > 0) {
            $list = Order::getInstance()->getListByConds($conditions, $page['offset'], $page['size']);
        }

        $this->view->setVars(
            [
                'list' => $list,
                'stime' => $stime,
                'etime' => $etime,
                'pageHtml' => PageFunction::getPageHtml(
                    $page['page'],
                    $total,
                    $page['size'],
                    parse_url($this->request->getURI())['path'],
                    ['stime' => $stime, 'etime' => $etime],
                    4
                )
            ]
        );
    }

}